package com.fiona.start.base;

import java.lang.annotation.Annotation;
import java.util.concurrent.CountDownLatch;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fiona.common.extension.Extension;
import com.fiona.start.IStart;

@Extension(order = 99)
public class AwaitStart implements IStart {
	private static Logger log = LoggerFactory.getLogger(AwaitStart.class);

	@Override
	public void start(Class<?> clazz) {

		Annotation[] annotations = clazz.getAnnotations();
		boolean isAwait = true;
		// 对于spring boot系统启动做特殊处理 begin
		for (int i = 0; i < annotations.length; i++) {
			if (annotations[i].getClass().getName().contains("SpringBootApplication")) {
				isAwait = false;
			}
		}
		// 对于spring boot系统启动做特殊处理 end
		if (isAwait) {
			CountDownLatch latch = new CountDownLatch(1);
			try {
				latch.await();
			} catch (InterruptedException e) {
				log.error("Fiona平台运行启动失败", e);
			}
		}
	}

}
